home *** CD-ROM | disk | FTP | other *** search
Text File | 1992-09-02 | 5.9 KB | 140 lines | [TEXT/CCL2] |
- (in-package ccl)
- (require 'graph-window)
- (export 'gdemo-window)
- (use-package '(:menus :common-lisp :common-lisp-user :ccl))
-
- (defun get-hidden-box ()
- (menus::get-wmgr))
-
- (defclass gdemo-window (menus:marking-menu-view pic-window)
- ()
- (:default-initargs
- :window-title "Graphic"
- :close-box-p t
- :auto-size t))
-
- (defmethod do-graphic-demo ((view gdemo-window))
- ;; creates a random drawing in a random-sized view
- ;; the drawing contains a filled oval and rectangle and a line
- (let* ((oval-corner (random-point 200 200 :xmin 60 :ymin 60))
- (oval-h (truncate (point-h oval-corner) 2))
- (oval-v (truncate (point-h oval-corner) 2))
- (rect-corner (random-point (+ oval-h 100) (+ oval-v 200)
- :xmin oval-h
- :ymin oval-v))
- (line-end (random-point 200 500 :xmin 150 :ymin 150))
- (xmax (apply #'max (mapcar #'point-h (list oval-corner rect-corner line-end))))
- (ymax (apply #'max (mapcar #'point-v (list oval-corner rect-corner line-end))))
- (new-size (add-points (make-point xmax ymax)
- #@(5 5)))
- my-view
- picture)
- (setq my-view (get-hidden-box))
- (with-focused-view my-view
- (rlet ((r :rect :topLeft #@(0 0) :bottomRight new-size))
- (setq picture (#_OpenPicture :ptr r))
- (fill-oval my-view *gray-pattern* #@(50 50) oval-corner)
- (frame-oval my-view #@(50 50) oval-corner)
- (set-pen-mode my-view :patxor)
- (fill-rect my-view *light-gray-pattern* (make-point oval-h oval-v) rect-corner)
- (set-pen-mode my-view :patcopy)
- (frame-rect my-view (make-point oval-h oval-v) rect-corner)
- (move-to my-view (random-point 150 150))
- (line-to my-view line-end)
- (#_closePicture)))
- (store-picture view picture)))
-
- (defmethod initialize-instance :after ((menus:marking-menu-view gdemo-window) &rest initargs)
- (declare (ignore initargs))
- (let ((enlarge (make-instance 'window-menu-item
- :menu-item-title "Enlarge"
- :disabled t))
-
- (reduce (make-instance 'window-menu-item
- :menu-item-title "Reduce"
- :disabled t))
-
- (new-pict (make-instance 'window-menu-item
- :menu-item-title "New"))
-
- (normal-size (make-instance 'window-menu-item
- :menu-item-title "Normal"
- :disabled t))
-
- (clear (make-instance 'window-menu-item
- :menu-item-title "Clear"
- :disabled t))
-
- (size (make-instance 'menu-item
- :menu-item-title "1 x"
- :disabled t))
-
- (close (make-instance 'window-menu-item
- :menu-item-title "Close"
- :menu-item-action
- #'(lambda (item)
- (window-close (menus:containing-view item))))))
- (cl-user::get-menu-options menus::marking-menu-view)
-
- (add-menu-items menus:marking-menu-view enlarge new-pict normal-size
- (make-instance 'menus:empty-menu-item)
- reduce size clear close)
-
- (setf (menu-item-action-function enlarge)
- #'(lambda (item)
- (let* ((view (menus:containing-view item))
- (scale (zoom-in view)))
- (if scale
- (set-menu-item-title size
- (progn (if (= scale 1)
- (menu-item-disable normal-size)
- (menu-item-enable normal-size))
- (menu-item-enable reduce)
- (format nil "~s x" scale)))
- (menu-item-disable enlarge))))
-
- (menu-item-action-function reduce)
- #'(lambda (item)
- (let* ((view (menus:containing-view item))
- (scale (zoom-out view)))
- (if scale
- (set-menu-item-title size
- (progn
- (if (= scale 1)
- (menu-item-disable normal-size)
- (menu-item-enable normal-size))
- (menu-item-enable enlarge)
- (format nil "~s x" scale)))
- (menu-item-disable reduce))))
-
- (menu-item-action-function new-pict)
- #'(lambda (item)
- (do-graphic-demo (menus:containing-view item))
- (menu-item-disable normal-size)
- (set-menu-item-title size (format nil "1 x"))
- (mapc #'menu-item-enable (list reduce enlarge clear)))
-
- (menu-item-action-function clear)
- #'(lambda (item)
- (clear (menus:containing-view item))
- (menu-item-disable normal-size)
- (set-menu-item-title size (format nil "Empty"))
- (mapc #'menu-item-disable (list reduce enlarge clear normal-size))
- nil)
-
- (menu-item-action-function normal-size)
- #'(lambda (item)
- (normal-size (menus:containing-view item))
- (set-menu-item-title size (format nil "1 x"))
- (menu-item-disable normal-size)
- (mapc #'menu-item-enable (list reduce enlarge))
- nil))))
-
- (defun random-point (xmax ymax &key xmin ymin)
- (let ((x (random (if xmin (- xmax xmin) xmax)))
- (y (random (if ymin (- ymax ymin) ymax))))
- (when xmin (incf x xmin))
- (when ymin (incf y ymin))
- (make-point x y)))
-
-